﻿using Newtonsoft.Json;

namespace Leo.Common.Json
{
    public class JsonMapper
    { 
        public static TResult MapTo<TResult>(object source)
        {
            if (source == null)
            {
                return default(TResult);
            }
            return JsonConvert.DeserializeObject<TResult>(JsonConvert.SerializeObject(source));
        }

        public static TResult MapTo<TResult>(object source, JsonSerializerSettings settings)
        {
            if (source == null)
            {
                return default(TResult);
            }
            return JsonConvert.DeserializeObject<TResult>(JsonConvert.SerializeObject(source, settings), settings);
        }
    }
}
